/**
 * author:龚佳新  
 * date:2013-11-27
 * 资产结构模型 方法全部抽取 为目前最精简模式
 */
Cnbi.model.Assets= function(params) {
   Cnbi.model.BaseSliderAndProgress.call(this,params); 
   var scope = this,domArray = params["domArray"];
   this.initPage=function(){
	      if(!scope.flag){//alert("子类的initPage");
	      		CnbiSoft.setCurrentRenderer("JavaScript");
	    	}

	   setFormula(false);
	   scope.setSliderValue(params.slider_array, scope.datas, "Idinput");
	   scope.setProgressValue(params.progress_array,scope.datas, "Idspan");
	   this.initChart(true);
	     	
    }
    
    this.initChart=function(action){   	  
    	  new Cnbi.model.Chart(getPieChartObj());
    	  var zzcbzv = params["judgeObj"]["zzcbzv"],zzczzv = params["judgeObj"]["zzczzv"];
    	  
		  var obj1={domId:domArray[0],datas:scope.datas[params["judgeObj"]["zzcbzv"]]-0,range:scope.industyParams[zzcbzv],title:'总资产报酬率'},
      	  obj2={domId:domArray[1],datas:scope.datas[params["judgeObj"]["zzczzv"]]-0,range:scope.industyParams[zzczzv],title:'总资产周转率'};
    	  
      	  if(action)new Cnbi.model.Chart(getAngularGaugeObj(obj1));
    	  if(action)new Cnbi.model.Chart(getAngularGaugeObj(obj2));
    	  }
    	  
    function getPieChartObj(){
    	return {chartType:1,//图表类型 ：0为单值数据图表;1为多单数据图表;2为多系数据图表
	            swfName:"Pie2d",//这个就不用说了吧！  //AngularGauge.swf
	            datas:[{index0:"",index1:""},[{index0:"负债总计",index1:scope.datas[params["judgeObj"]["fzzj"]]},{index0:"流动资产",index1:scope.datas[params["judgeObj"]["ldzc"]]},{index0:"非流动资产",index1:scope.datas[params["judgeObj"]["fldzc"]]},{index0:"所有者权益",index1:scope.datas[params["judgeObj"]["syzqyhj"]]}]],//   scope.datas["fldzc"]显示的数据  注意：规定的数据解析格式
	            domId:domArray[2],//渲染的dom节点
	            percent:true,
	            color:["1C86EE","EEC900","6B8E23","9400D3","FF0000"], //颜色
	          	attributes:'manageResize="1"  showLabels="1" formatNumberScale="0" chartTopMargin="-10" chartLeftMargin="-20"  legendAllowDrag="0" minimiseWrappingInLegend="0" showBorder="0"   legendBorderThickness="0" legendBorderColor="ffffff" legendBorderAlpha="0" bgColor="ffffff" bgAlpha="0,0" showValues="0" isSmartLineSlanted="1" pieSliceDepth="100"  showLegend="0"',//numberPrefix="￥" 
	          	width:"180%",
	          	height:"100%"
	          	}
    };	  
    
    var upperLimit = 0.00;
    function getAngularGaugeObj(params){
    	var range = params["range"];upperLimit=range["excellent"]-0;	
     	if((params["datas"]-0)>upperLimit){
     		upperLimit = params["datas"]-0;
     	}
     	
     	var dialsAttr=' radius="70" baseWidth="20" topWidth="2" color="296CAF,000000" fillRatio="90, 10" borderColor="8C7EFF"  valueY="155" ',
        attributes='manageResize="1" showValue="1"  origW="330" showBorder="0" origH="170" showTickValues="0" numberSuffix="%" baseFontColor="000000" animation="1" autoAlignTickValues="1"  tickValueDistance="1" bgColor="FFFFFF" bgAlpha="0" lowerLimit="'+range["lowers"]+'" upperLimit="'+upperLimit+'" gaugeStartAngle="180" gaugeEndAngle="0" gaugeOuterRadius="-80" gaugeInnerRadius="100" gaugeOriginX="165" gaugeOriginY="130" minorTMNumber="5" majorTMColor="000000" minorTMColor="000000" majorTMHeight="15" majorTMThickness="1" minorTMHeight="10" minorTMThickness="1" decmials="2" placeValuesInside="1" pivotFillMix="87CEFF, 25588A" pivotFillRatio="50,50" pivotBorderThickness="40" pivotBorderColor="CCCCCC" pivotRadius="15" showShadow="0" toolTipBgColor="FFFFFF"',
    	annotations='<annotationGroup id="Grp1" showBelow="1" x="165" y="131">'+
                   		'<annotation type="arc" x="0" y="7" radius="115" innerRadius="0" startAngle="0" endAngle="180" fillAngle="90" fillRatio="10,90" color="80ACD7, FFFFFF" fillPattern="linear" borderColor="B9CEE2" borderThickness="10" />'+
                   		'<annotation type="circle"  radius="21"  fillAlpha="0" borderColor="" borderThickness="2" borderAlpha="60" />'+
                	'</annotationGroup>',
        trendpoints='<point startValue="'+range["lowers"]+'" endValue="'+range["average"]+'" valueInside="0" color="FF0000" innerRadius="115" alpha="100" />' +
      			  '<point startValue="'+range["average"]+'" endValue="'+range["good"]+'" valueInside="0" color="EEC900" innerRadius="115" alpha="100" />' +
      			  '<point startValue="'+range["good"]+'" endValue="'+range["excellent"]+'" valueInside="0" color="00CD00" innerRadius="115" alpha="100" />',
        styles='<definition><style name="LimitFont" type="font" face="Verdana" size="13"  bold="1"/><style name="pivotGlow" type="glow" color="FFFFFF" /></definition>'+
              '<application><apply toObject="VALUE" styles="LimitFont" /><apply toObject="PIVOT" styles="pivotGlow" /></application>';
     	return {chartType:0,//图表类型 ：0为单值数据图表;1为多单数据图表;2为多系数据图表
	            swfName:"AngularGauge",//这个就不用说了吧！  //AngularGauge.swf
	            datas:params["datas"],//显示的数据  注意：规定的数据解析格式  numberSuffix="%"
	            domId:params["domId"],//渲染的dom节点
	            attributes:attributes,
	            color:["FF0000","EEC900","00CD00"], //颜色good 
	            dialsAttr:dialsAttr,
	            styles:styles,
	           // trendpoints:trendpoints,
	            annotations:annotations,
	          	colorRange:[range["lowers"],range["average"],range["good"],upperLimit],//chartType==0时才有此属性
	          	width:"90%",height:"20%"};
    };
    
    function updateTip(){
       var ldzczcv = scope.datas[params["judgeObj"]["ldzczcv"]],yysrzcv = scope.datas[params["judgeObj"]["yysrzcv"]]
       if((ldzczcv-0)>(yysrzcv-0)){    	   
    	   $("#zczkspan").html("<font color='green'>总体来看，流动资产增长快于营业收入增长，并且<br>资产的盈利能力有所提高,资产结构趋于改善!。</font>");
  	   }else {
  		   $("#zczkspan").html("<font color='red'>总体来看,虽然流动资产增长慢于营业收入增长，但<br>资产的盈利能力没有提高，资产结构有待提高！</font>");
  	   };
    }
    
    this.updataInputAfter=function(id ,value,datas ){		
		setFormula(true); 
		updateTip();
	};
	
	function setFormula(action) {
		//var zzcbzv = params["judgeObj"]["zzcbzv"],zzczzv = params["judgeObj"]["zzczzv"];
		//console.dir("哈哈啊哈哈哈"+action);
		scope.initBefore();
		var  chartId=domArray[0].toString()+domArray[3].toString();
		
	    if(getChartFromId(chartId)){
	       //getChartFromId(chartId).setData(1,scope.datas[params["judgeObj"]["zzcbzv"]]);
	       var tempData = scope.datas[params["judgeObj"]["zzcbzv"]]-0;
		   if((scope.datas[params["judgeObj"]["zzcbzv"]]-0)> upperLimit){
		       tempData =upperLimit;
		   }
		   getChartFromId(chartId).setData(1,tempData);
	    }
	       
	  	chartId=domArray[1].toString()+domArray[3].toString();
	  	if(getChartFromId(chartId)){
	  	   //getChartFromId(chartId).setData(1, scope.datas[params["judgeObj"]["zzczzv"]]);
	  		
	  	   var tempData = scope.datas[params["judgeObj"]["zzczzv"]]-0;
		   if((scope.datas[params["judgeObj"]["zzczzv"]]-0)> upperLimit){
		       tempData =upperLimit;
		   }
		   getChartFromId(chartId).setData(1,tempData);
	    }
			   	      
	}
	
   	scope.init();
}
Ext.onReady(function(){
	var slider_array=module["sliderItemScode"].split(",");
	var params ={itemIndex:module["queryItemScode"],showDim:'item',povitDim:'item',queryFact:'B',company:'EVA1',type:"assets",year :qj.year,month :qj.month,unit :qj.unit};
    var toolsMap = module["toolsMap"];
    var bean =  new Cnbi.model.Assets({
		//id:'assets',
    	id:module["id"],
		slider_array:slider_array,
		params:params,
		progress_array:[
		    toolsMap["zcfzv"]["scode"],
		    toolsMap["ldzczcv"]["scode"], 
		    toolsMap["yysrzcv"]["scode"]],
		updateInput:'Idinput',
		pro:{width:170},
		sli:{width:155},
		domArray:["zzcbzvId","zzczzvId","chartId","_cnbi_chartId"],
		companyName:company["text"],
		//indi:module["formulas"]["db_formulas"],//从数据库找的公式ID群
		//zIndicator:module["formulas"]["userDefined_formulas"],//自定义公式群 zcfzv
		judgeObj:{
		          syzqyhj:toolsMap["syzqyhj"]["scode"],
		          ldzc:toolsMap["ldzc"]["scode"],
		          fzzj:toolsMap["fzzj"]["scode"],
		          fldzc:toolsMap["fldzc"]["scode"],
		          zcfzv:toolsMap["zcfzv"]["scode"],
		          ldzczcv:toolsMap["ldzczcv"]["scode"],
		          yysrzcv:toolsMap["yysrzcv"]["scode"],
		          zzcbzv:toolsMap["zzcbzv"]["scode"],
		          zzczzv:toolsMap["zzczzv"]["scode"]
		         },
		//assistsFormulas:module["formulas"]["assists_formulas"],
		module:module
	 }); 	 	
});